﻿using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq.Expressions;

namespace OA.Model
{
    //[TableName("管理员")]
    [Table("Admin")]
    public class AdminInfo : BaseInfo
    {
        public int Status { get; set; }

        [Display(Name = "用户名")]
        [MaxLength(20)]
        [Required(ErrorMessage = "用户名不能为空")]
       // [Index(name: "UserName", IsClustered = false, IsUnique = true, Order = 1)]
        public string UserName { get; set; }

        [Display(Name = "密码")]
        [Required(ErrorMessage = "不能为空")]
        [MaxLength(32)]
        public string PassWord { get; set; }

        /// <summary>
        /// 姓名
        /// </summary>
        [Display(Name = "姓名")]
        [MaxLength(20)]
        public string RealName { get; set; }

        /// <summary>
        /// 电话号码
        /// </summary>
        [Display(Name = "电话号码")]
        [MaxLength(30)]
        public string Mobile { get; set; }

        public DateTime? LockTime { get; set; }

        public int ErrorTimes { get; set; }

    }

    public class SimpleAdmin : SimpleInfo
    {
 
        public string UserName { get; set; }
         
        public string RealName { get; set; }        

        public string StatusName {
            get
            {
                if (this.Status == -1)
                {
                    return "已禁用";
                }
                else
                {
                    return "正常";
                }
            }
        }

        public static Expression<Func<AdminInfo, SimpleAdmin>> Map = m => new SimpleAdmin()
        {
            ID = m.ID,
            UserName = m.UserName,
            Status = m.Status,
            RealName = m.RealName
        };

    }
}
